<?php
/**
 * 年龄检查
 * User: GRAY
 * Date: 16/8/11
 * Time: 下午10:23
 */

namespace Home\Common\Hook;


use Common\Library\BusinessException;
use Common\Library\Constant;
use Common\Vendor\Hook\BaseHook;
use Think\Log;


class UserInfo extends BaseHook
{

    public function execute($data, $params = [])
    {
        $hook_user_info_pass = $data['hook_user_info_pass'];
        if($hook_user_info_pass ==1) {
            return $data;
        }
        $id_num = $data["id_num"];
        if(empty($id_num) && $params["no_idcard_no_pass"]){
    	    BusinessException::throwException(Constant::INVALID_NO_ID_CARD);
        }

        $valid_period = $data["valid_period"];
        $begin_end_time = explode('-',$valid_period);
        if(count($begin_end_time) != 2){
    	    BusinessException::throwException(Constant::INVALID_IDCARD_PERIOD);
        }
        $begin_time = $begin_end_time[0];
        $end_time = $begin_end_time[1];
        $diff_days = (strtotime(str_replace(".","-",$end_time)) - time())*1.0/86400;
        if($diff_days <  $params["less_than_day_num_no_pass"]){
    	    BusinessException::throwException(Constant::INVALID_ID_NUM_PERIOD);
        }
        return $data;
    }
} 
